{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#hide\n",
    "#skip\n",
    "! [ -e /content ] && pip install -Uqq fastai  # upgrade fastai on colab"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "convert pip wheel -> conda package\n",
    "\n",
    "whl   zip\n",
    " - contains cymem-2.0.2.dist-info : LICENSE  METADATA  RECORD  top_level.txt  WHEEL\n",
    "\n",
    "conda tgz\n",
    " - includes lib/python{v}/site-packages/\n",
    " - contains info : \"about.json  files  git  hash_input.json  index.json  paths.json\"\n",
    "\n",
    "conversion:\n",
    "\n",
    "1. move main modules to lib/...\n",
    "2. create info\n",
    "\n",
    "---\n",
    "\n",
    "- about: home license summary\n",
    "- files: list\n",
    "- git: empty\n",
    "- hash_input: empty\n",
    "- index.json: create\n",
    "- paths: files with sha256 and size"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from fastai.torch_basics import *\n",
    "import zipfile,tarfile\n",
    "from email.parser import Parser\n",
    "from wheel import wheelfile"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from conda.gateways.disk.read import read_python_record"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(True, True)"
      ]
     },
     "execution_count": null,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "path = Path('~/git/spacy_conda/cymem').expanduser()\n",
    "pkg = path/'pkg/cymem-2.0.2-py37_0.tar.bz2'\n",
    "whl = path/'whl/cymem-2.0.2-cp37-cp37m-manylinux1_x86_64.whl'\n",
    "pkg.exists(),whl.exists()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "zpkg = tarfile.open(pkg,\"r:bz2\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[(0, 'info/hash_input.json'),\n",
       " (1, 'info/index.json'),\n",
       " (2, 'info/files'),\n",
       " (3, 'info/paths.json'),\n",
       " (4, 'info/about.json'),\n",
       " (5, 'info/git')]"
      ]
     },
     "execution_count": null,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lpkg = zpkg.getmembers()\n",
    "[(i,o.name) for i,o in enumerate(lpkg) if o.name.startswith('info/')]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "  \"channels\": [\n",
      "    \"pytorch\",\n",
      "    \"fastai\",\n",
      "    \"defaults\"\n",
      "  ],\n",
      "  \"conda_build_version\": \"3.18.8\",\n",
      "  \"conda_private\": false,\n",
      "  \"conda_version\": \"4.7.12\",\n",
      "  \"env_vars\": {\n",
      "    \"CIO_TEST\": \"<not set>\"\n",
      "  },\n",
      "  \"extra\": {\n",
      "    \"copy_test_source_files\": true,\n",
      "    \"final\": true\n",
      "  },\n",
      "  \"home\": \"https://github.com/explosion/cymem\",\n",
      "  \"identifiers\": [],\n",
      "  \"keywords\": [],\n",
      "  \"license\": \"MIT\",\n",
      "  \"root_pkgs\": [\n",
      "    \"partd 1.0.0 py_0\",\n",
      "    \"nltk 3.4.5 py37_0\",\n",
      "    \"beautifulsoup4 4.8.0 py37_0\",\n",
      "    \"sphinxcontrib-htmlhelp 1.0.2 py_0\",\n",
      "    \"wheel 0.33.6 py37_0\",\n",
      "    \"mock 3.0.5 py37_0\",\n",
      "    \"numpy-base 1.17.2 py37hde5b4d6_0\",\n",
      "    \"qtpy 1.9.0 py_0\",\n",
      "    \"mistune 0.8.4 py37h7b6447c_0\",\n",
      "    \"bitarray 1.0.1 py37h7b6447c_0\",\n",
      "    \"libtiff 4.0.10 h2733197_2\",\n",
      "    \"mpc 1.1.0 h10f8cd9_1\",\n",
      "    \"cryptography 2.7 py37h1ba5d50_0\",\n",
      "    \"pytest-astropy 0.5.0 py37_0\",\n",
      "    \"krb5 1.16.1 h173b8e3_7\",\n",
      "    \"libssh2 1.8.2 h1ba5d50_0\",\n",
      "    \"anaconda custom py37_1\",\n",
      "    \"ipython 7.8.0 py37h39e3cac_0\",\n",
      "    \"zlib 1.2.11 h7b6447c_3\",\n",
      "    \"pytest 5.1.2 py37_0\",\n",
      "    \"clyent 1.2.2 py37_1\",\n",
      "    \"werkzeug 0.16.0 py_0\",\n",
      "    \"libarchive 3.3.3 h5d8350f_5\",\n",
      "    \"pep8 1.7.1 py37_0\",\n",
      "    \"sqlalchemy 1.3.8 py37h7b6447c_0\",\n",
      "    \"cffi 1.12.3 py37h2e261b9_0\",\n",
      "    \"pycurl 7.43.0.3 py37h1ba5d50_0\",\n",
      "    \"cloudpickle 1.2.2 py_0\",\n",
      "    \"sphinx 2.2.0 py_0\",\n",
      "    \"ripgrep 0.10.0 hc07d326_0\",\n",
      "    \"pexpect 4.7.0 py37_0\",\n",
      "    \"itsdangerous 1.1.0 py37_0\",\n",
      "    \"pango 1.42.4 h049681c_0\",\n",
      "    \"mkl 2019.4 243\",\n",
      "    \"sympy 1.4 py37_0\",\n",
      "    \"soupsieve 1.9.3 py37_0\",\n",
      "    \"networkx 2.3 py_0\",\n",
      "    \"sphinxcontrib-serializinghtml 1.1.3 py_0\",\n",
      "    \"jeepney 0.4.1 py_0\",\n",
      "    \"llvmlite 0.29.0 py37hd408876_0\",\n",
      "    \"wurlitzer 1.0.3 py37_0\",\n",
      "    \"jupyter_console 6.0.0 py37_0\",\n",
      "    \"pyparsing 2.4.2 py_0\",\n",
      "    \"numba 0.45.1 py37h962f231_0\",\n",
      "    \"defusedxml 0.6.0 py_0\",\n",
      "    \"tk 8.6.8 hbc83047_0\",\n",
      "    \"jupyter 1.0.0 py37_7\",\n",
      "    \"libpng 1.6.37 hbc83047_0\",\n",
      "    \"xlrd 1.2.0 py37_0\",\n",
      "    \"locket 0.2.0 py37_1\",\n",
      "    \"psutil 5.6.3 py37h7b6447c_0\",\n",
      "    \"backports.os 0.1.1 py37_0\",\n",
      "    \"spyder-kernels 0.5.2 py37_0\",\n",
      "    \"numexpr 2.7.0 py37h9e4a6bb_0\",\n",
      "    \"json5 0.8.5 py_0\",\n",
      "    \"imageio 2.5.0 py37_0\",\n",
      "    \"boto 2.49.0 py37_0\",\n",
      "    \"simplegeneric 0.8.1 py37_2\",\n",
      "    \"patchelf 0.9 he6710b0_3\",\n",
      "    \"libgcc-ng 9.1.0 hdf63c60_0\",\n",
      "    \"pyodbc 4.0.27 py37he6710b0_0\",\n",
      "    \"ninja 1.9.0 py37hfd86e86_0\",\n",
      "    \"prompt_toolkit 2.0.9 py37_0\",\n",
      "    \"lz4-c 1.8.1.2 h14c3975_0\",\n",
      "    \"joblib 0.13.2 py37_0\",\n",
      "    \"olefile 0.46 py37_0\",\n",
      "    \"scikit-image 0.15.0 py37he6710b0_0\",\n",
      "    \"sphinxcontrib-applehelp 1.0.1 py_0\",\n",
      "    \"ruamel_yaml 0.15.46 py37h14c3975_0\",\n",
      "    \"setuptools 41.2.0 py37_0\",\n",
      "    \"chardet 3.0.4 py37_1003\",\n",
      "    \"gmp 6.1.2 h6c8ec71_1\",\n",
      "    \"pyyaml 5.1.2 py37h7b6447c_0\",\n",
      "    \"conda-env 2.6.0 1\",\n",
      "    \"certifi 2019.9.11 py37_0\",\n",
      "    \"fsspec 0.5.1 py_0\",\n",
      "    \"h5py 2.9.0 py37h7918eee_0\",\n",
      "    \"_anaconda_depends 2019.03 py37_0\",\n",
      "    \"testpath 0.4.2 py37_0\",\n",
      "    \"cairo 1.14.12 h8948797_3\",\n",
      "    \"get_terminal_size 1.0.0 haa9412d_0\",\n",
      "    \"sip 4.19.8 py37hf484d3e_0\",\n",
      "    \"unicodecsv 0.14.1 py37_0\",\n",
      "    \"anaconda-navigator 1.9.7 py37_0\",\n",
      "    \"isort 4.3.21 py37_0\",\n",
      "    \"harfbuzz 1.8.8 hffaf4a1_0\",\n",
      "    \"sphinxcontrib-websupport 1.1.2 py_0\",\n",
      "    \"libxcb 1.13 h1bed415_1\",\n",
      "    \"statsmodels 0.10.1 py37hdd07704_0\",\n",
      "    \"libtool 2.4.6 h7b6447c_5\",\n",
      "    \"nbformat 4.4.0 py37_0\",\n",
      "    \"zeromq 4.3.1 he6710b0_3\",\n",
      "    \"glob2 0.7 py_0\",\n",
      "    \"fribidi 1.0.5 h7b6447c_0\",\n",
      "    \"libxml2 2.9.9 hea5a465_1\",\n",
      "    \"mpmath 1.1.0 py37_0\",\n",
      "    \"sqlite 3.29.0 h7b6447c_0\",\n",
      "    \"kiwisolver 1.1.0 py37he6710b0_0\",\n",
      "    \"backports.weakref 1.0.post1 py_1\",\n",
      "    \"bottleneck 1.2.1 py37h035aef0_1\",\n",
      "    \"filelock 3.0.12 py_0\",\n",
      "    \"fontconfig 2.13.0 h9420a91_0\",\n",
      "    \"intel-openmp 2019.4 243\",\n",
      "    \"jsonschema 3.0.2 py37_0\",\n",
      "    \"nose 1.3.7 py37_2\",\n",
      "    \"readline 7.0 h7b6447c_5\",\n",
      "    \"wrapt 1.11.2 py37h7b6447c_0\",\n",
      "    \"icu 58.2 h9c2bf20_1\",\n",
      "    \"openpyxl 2.6.3 py_0\",\n",
      "    \"sortedcontainers 2.1.0 py37_0\",\n",
      "    \"pytz 2019.2 py_0\",\n",
      "    \"snappy 1.1.7 hbae5bb6_3\",\n",
      "    \"pytest-openfiles 0.4.0 py_0\",\n",
      "    \"docutils 0.15.2 py37_0\",\n",
      "    \"py-lief 0.9.0 py37h7725739_2\",\n",
      "    \"asn1crypto 0.24.0 py37_0\",\n",
      "    \"xlsxwriter 1.2.1 py_0\",\n",
      "    \"python-dateutil 2.8.0 py37_0\",\n",
      "    \"backcall 0.1.0 py37_0\",\n",
      "    \"html5lib 1.0.1 py37_0\",\n",
      "    \"babel 2.7.0 py_0\",\n",
      "    \"decorator 4.4.0 py37_1\",\n",
      "    \"gstreamer 1.14.0 hb453b48_1\",\n",
      "    \"gst-plugins-base 1.14.0 hbbd80ab_1\",\n",
      "    \"tblib 1.4.0 py_0\",\n",
      "    \"sphinxcontrib-qthelp 1.0.2 py_0\",\n",
      "    \"click 7.0 py37_0\",\n",
      "    \"pytables 3.5.2 py37h71ec239_1\",\n",
      "    \"pytest-doctestplus 0.4.0 py_0\",\n",
      "    \"fastcache 1.1.0 py37h7b6447c_0\",\n",
      "    \"blosc 1.16.3 hd408876_0\",\n",
      "    \"ca-certificates 2019.8.28 0\",\n",
      "    \"ipywidgets 7.5.1 py_0\",\n",
      "    \"hdf5 1.10.4 hb1b8bf9_0\",\n",
      "    \"pillow 6.1.0 py37h34e0f95_0\",\n",
      "    \"pycosat 0.6.3 py37h14c3975_0\",\n",
      "    \"distributed 2.4.0 py_0\",\n",
      "    \"jupyterlab_server 1.0.6 py_0\",\n",
      "    \"seaborn 0.9.0 py37_0\",\n",
      "    \"heapdict 1.0.1 py_0\",\n",
      "    \"pickleshare 0.7.5 py37_0\",\n",
      "    \"jupyterlab 1.1.4 pyhf63ae98_0\",\n",
      "    \"cytoolz 0.10.0 py37h7b6447c_0\",\n",
      "    \"ply 3.11 py37_0\",\n",
      "    \"mkl_fft 1.0.14 py37ha843d7b_0\",\n",
      "    \"navigator-updater 0.2.1 py37_0\",\n",
      "    \"bzip2 1.0.8 h7b6447c_0\",\n",
      "    \"backports.tempfile 1.0 py_1\",\n",
      "    \"prometheus_client 0.7.1 py_0\",\n",
      "    \"qtconsole 4.5.5 py_0\",\n",
      "    \"anaconda-project 0.8.3 py_0\",\n",
      "    \"astropy 3.2.1 py37h7b6447c_0\",\n",
      "    \"widgetsnbextension 3.5.1 py37_0\",\n",
      "    \"lxml 4.4.1 py37hefd8a0e_0\",\n",
      "    \"keyring 18.0.0 py37_0\",\n",
      "    \"jedi 0.15.1 py37_0\",\n",
      "    \"pywavelets 1.0.3 py37hdd07704_1\",\n",
      "    \"pyzmq 18.1.0 py37he6710b0_0\",\n",
      "    \"send2trash 1.5.0 py37_0\",\n",
      "    \"pandas 0.25.1 py37he6710b0_0\",\n",
      "    \"six 1.12.0 py37_0\",\n",
      "    \"snowballstemmer 1.9.1 py_0\",\n",
      "    \"pycparser 2.19 py37_0\",\n",
      "    \"mpfr 4.0.1 hdf1c602_3\",\n",
      "    \"scipy 1.3.1 py37h7c811a0_0\",\n",
      "    \"secretstorage 3.1.1 py37_0\",\n",
      "    \"backports.functools_lru_cache 1.5 py_2\",\n",
      "    \"zipp 0.6.0 py_0\",\n",
      "    \"_ipyw_jlab_nb_ext_conf 0.1.0 py37_0\",\n",
      "    \"importlib_metadata 0.23 py37_0\",\n",
      "    \"pandocfilters 1.4.2 py37_1\",\n",
      "    \"pysocks 1.7.1 py37_0\",\n",
      "    \"alabaster 0.7.12 py37_0\",\n",
      "    \"parso 0.5.1 py_0\",\n",
      "    \"blas 1.0 mkl\",\n",
      "    \"astroid 2.2.5 py37_0\",\n",
      "    \"libxslt 1.1.33 h7d1a2b0_0\",\n",
      "    \"ptyprocess 0.6.0 py37_0\",\n",
      "    \"bokeh 1.3.4 py37_0\",\n",
      "    \"msgpack-python 0.6.1 py37hfd86e86_1\",\n",
      "    \"gevent 1.4.0 py37h7b6447c_0\",\n",
      "    \"conda 4.7.12 py37_0\",\n",
      "    \"py 1.8.0 py37_0\",\n",
      "    \"bleach 3.1.0 py37_0\",\n",
      "    \"flask 1.1.1 py_0\",\n",
      "    \"terminado 0.8.2 py37_0\",\n",
      "    \"conda-verify 3.4.2 py_1\",\n",
      "    \"python-libarchive-c 2.8 py37_13\",\n",
      "    \"libstdcxx-ng 9.1.0 hdf63c60_0\",\n",
      "    \"qt 5.9.7 h5867ecd_1\",\n",
      "    \"entrypoints 0.3 py37_0\",\n",
      "    \"gmpy2 2.0.8 py37h10f8cd9_2\",\n",
      "    \"matplotlib 3.1.1 py37h5429711_0\",\n",
      "    \"atomicwrites 1.3.0 py37_1\",\n",
      "    \"jpeg 9b h024ee3a_2\",\n",
      "    \"traitlets 4.3.2 py37_0\",\n",
      "    \"pycodestyle 2.5.0 py37_0\",\n",
      "    \"pytest-arraydiff 0.3 py37h39e3cac_0\",\n",
      "    \"singledispatch 3.4.0.3 py37_0\",\n",
      "    \"requests 2.22.0 py37_0\",\n",
      "    \"expat 2.2.6 he6710b0_0\",\n",
      "    \"unixodbc 2.3.7 h14c3975_0\",\n",
      "    \"python 3.7.3 h0371630_0\",\n",
      "    \"jinja2 2.10.1 py37_0\",\n",
      "    \"pyopenssl 19.0.0 py37_0\",\n",
      "    \"zict 1.0.0 py_0\",\n",
      "    \"xlwt 1.3.0 py37_0\",\n",
      "    \"et_xmlfile 1.0.1 py37_0\",\n",
      "    \"idna 2.8 py37_0\",\n",
      "    \"imagesize 1.1.0 py37_0\",\n",
      "    \"spyder 3.3.6 py37_0\",\n",
      "    \"backports 1.0 py_2\",\n",
      "    \"numpydoc 0.9.1 py_0\",\n",
      "    \"jupyter_client 5.3.3 py37_1\",\n",
      "    \"_libgcc_mutex 0.1 main\",\n",
      "    \"mkl-service 2.3.0 py37he904b0f_0\",\n",
      "    \"sortedcollections 1.1.2 py37_0\",\n",
      "    \"torchvision 0.4.0 py37_cu100\",\n",
      "    \"webencodings 0.5.1 py37_1\",\n",
      "    \"anaconda-client 1.7.2 py37_0\",\n",
      "    \"pylint 2.3.1 py37_0\",\n",
      "    \"rope 0.14.0 py_0\",\n",
      "    \"cycler 0.10.0 py37_0\",\n",
      "    \"qtawesome 0.6.0 py_0\",\n",
      "    \"mkl_random 1.1.0 py37hd6b4f25_0\",\n",
      "    \"pyrsistent 0.15.4 py37h7b6447c_0\",\n",
      "    \"pixman 0.38.0 h7b6447c_0\",\n",
      "    \"pcre 8.43 he6710b0_0\",\n",
      "    \"more-itertools 7.2.0 py37_0\",\n",
      "    \"cudatoolkit 10.0.130 0\",\n",
      "    \"dbus 1.13.6 h746ee38_0\",\n",
      "    \"ipython_genutils 0.2.0 py37_0\",\n",
      "    \"tornado 6.0.3 py37h7b6447c_0\",\n",
      "    \"libffi 3.2.1 hd88cf55_4\",\n",
      "    \"jbig 2.1 hdba287a_0\",\n",
      "    \"cython 0.29.13 py37he6710b0_0\",\n",
      "    \"openssl 1.1.1d h7b6447c_1\",\n",
      "    \"libuuid 1.0.3 h1bed415_2\",\n",
      "    \"mccabe 0.6.1 py37_1\",\n",
      "    \"tbb 2019.4 hfd86e86_0\",\n",
      "    \"lzo 2.10 h49e0be7_2\",\n",
      "    \"multipledispatch 0.6.0 py37_0\",\n",
      "    \"libcurl 7.65.3 h20c2e04_0\",\n",
      "    \"pluggy 0.13.0 py37_0\",\n",
      "    \"ncurses 6.1 he6710b0_1\",\n",
      "    \"pkginfo 1.5.0.1 py37_0\",\n",
      "    \"dask 2.4.0 py_0\",\n",
      "    \"lazy-object-proxy 1.4.2 py37h7b6447c_0\",\n",
      "    \"libgfortran-ng 7.3.0 hdf63c60_0\",\n",
      "    \"conda-build 3.18.8 py37_0\",\n",
      "    \"zstd 1.3.7 h0b5b093_0\",\n",
      "    \"liblief 0.9.0 h7725739_2\",\n",
      "    \"glib 2.56.2 hd408876_0\",\n",
      "    \"pathlib2 2.3.4 py37_0\",\n",
      "    \"pip 19.2.3 py37_0\",\n",
      "    \"pyflakes 2.1.1 py37_0\",\n",
      "    \"markupsafe 1.1.1 py37h7b6447c_0\",\n",
      "    \"yaml 0.1.7 had09818_2\",\n",
      "    \"greenlet 0.4.15 py37h7b6447c_0\",\n",
      "    \"toolz 0.10.0 py_0\",\n",
      "    \"pytorch 1.2.0 py3.7_cuda10.0.130_cudnn7.6.2_0\",\n",
      "    \"future 0.17.1 py37_0\",\n",
      "    \"scikit-learn 0.21.3 py37hd81dba3_0\",\n",
      "    \"attrs 19.1.0 py37_1\",\n",
      "    \"jdcal 1.4.1 py_0\",\n",
      "    \"pyqt 5.9.2 py37h05f1152_2\",\n",
      "    \"pytest-remotedata 0.3.2 py37_0\",\n",
      "    \"curl 7.65.3 hbc83047_0\",\n",
      "    \"xz 5.2.4 h14c3975_4\",\n",
      "    \"ipykernel 5.1.2 py37h39e3cac_0\",\n",
      "    \"contextlib2 0.6.0 py_0\",\n",
      "    \"jupyter_core 4.5.0 py_0\",\n",
      "    \"pygments 2.4.2 py_0\",\n",
      "    \"conda-package-handling 1.6.0 py37h7b6447c_0\",\n",
      "    \"pandoc 2.2.3.2 0\",\n",
      "    \"sphinxcontrib-jsmath 1.0.1 py_0\",\n",
      "    \"backports.shutil_get_terminal_size 1.0.0 py37_2\",\n",
      "    \"nbconvert 5.6.0 py37_1\",\n",
      "    \"dask-core 2.4.0 py_0\",\n",
      "    \"freetype 2.9.1 h8a8886c_1\",\n",
      "    \"numpy 1.17.2 py37haad9e8e_0\",\n",
      "    \"graphite2 1.3.13 h23475e2_0\",\n",
      "    \"sphinxcontrib 1.0 py37_1\",\n",
      "    \"path.py 12.0.1 py_0\",\n",
      "    \"packaging 19.2 py_0\",\n",
      "    \"pycrypto 2.6.1 py37h14c3975_9\",\n",
      "    \"patsy 0.5.1 py37_0\",\n",
      "    \"wcwidth 0.1.7 py37_0\",\n",
      "    \"libedit 3.1.20181209 hc058e9b_0\",\n",
      "    \"notebook 6.0.1 py37_0\",\n",
      "    \"libsodium 1.0.16 h1bed415_0\",\n",
      "    \"sphinxcontrib-devhelp 1.0.1 py_0\",\n",
      "    \"bkcharts 0.2 py37_0\",\n",
      "    \"colorama 0.4.1 py37_0\",\n",
      "    \"urllib3 1.24.2 py37_0\",\n",
      "    \"tqdm 4.36.1 py_0\"\n",
      "  ],\n",
      "  \"summary\": \"Manage calls to calloc/free through Cython\",\n",
      "  \"tags\": []\n",
      "}\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'info/index.json'"
      ]
     },
     "execution_count": null,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "f = (zpkg.extractfile('info/about.json').read().decode())\n",
    "print(f)\n",
    "fn.name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "fwhl = wheelfile.WheelFile(whl)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'namever': 'cymem-2.0.2',\n",
       " 'name': 'cymem',\n",
       " 'ver': '2.0.2',\n",
       " 'build': None,\n",
       " 'pyver': 'cp37',\n",
       " 'abi': 'cp37m',\n",
       " 'plat': 'manylinux1_x86_64'}"
      ]
     },
     "execution_count": null,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fwhl.parsed_filename.groupdict()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'cymem-2.0.2.dist-info'"
      ]
     },
     "execution_count": null,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fwhl.dist_info_path"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'cymem-2.0.2.dist-info/RECORD'"
      ]
     },
     "execution_count": null,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fwhl.record_path"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(PathDataV1(_path='lib/python3.7/site-packages/cymem-2.0.2.dist-info/LICENSE', path_type='hardlink', sha256='ednboUtKqeqeBouyYb59GvQN9K04gEyyw2KwK5cPxHo', size_in_bytes=1139),\n",
       " PathDataV1(_path='lib/python3.7/site-packages/cymem-2.0.2.dist-info/METADATA', path_type='hardlink', sha256='9tePG2KbFvrQ1Sy86GeZfihXDryyKcI1jS_7ZDcrTjc', size_in_bytes=8585),\n",
       " PathDataV1(_path='lib/python3.7/site-packages/cymem-2.0.2.dist-info/RECORD', path_type='hardlink', sha256=None, size_in_bytes=None),\n",
       " PathDataV1(_path='lib/python3.7/site-packages/cymem-2.0.2.dist-info/WHEEL', path_type='hardlink', sha256='QNlK5ivAimyKC6GBwwJ1xZo1FLZqOgbKwJoOKciA_fE', size_in_bytes=109),\n",
       " PathDataV1(_path='lib/python3.7/site-packages/cymem-2.0.2.dist-info/top_level.txt', path_type='hardlink', sha256='dCYwCFWTj_NE7Z9zFrrKqAcWuUCtg52zKRI4l_Wrr7Q', size_in_bytes=6),\n",
       " PathDataV1(_path='lib/python3.7/site-packages/cymem/__init__.pxd', path_type='hardlink', sha256='47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU', size_in_bytes=0),\n",
       " PathDataV1(_path='lib/python3.7/site-packages/cymem/__init__.py', path_type='hardlink', sha256='SZPicygro0c1rh3QY-iN21ZormYrSBeim1R2DSeaOH4', size_in_bytes=21),\n",
       " PathDataV1(_path='lib/python3.7/site-packages/cymem/__pycache__/__init__.cpython-37.pyc', path_type='hardlink', sha256=None, size_in_bytes=None),\n",
       " PathDataV1(_path='lib/python3.7/site-packages/cymem/__pycache__/about.cpython-37.pyc', path_type='hardlink', sha256=None, size_in_bytes=None),\n",
       " PathDataV1(_path='lib/python3.7/site-packages/cymem/about.py', path_type='hardlink', sha256='7Xg2PhAIoeQIQPl1j47Cs8xRWscmh_-0NZeg96zh7Sg', size_in_bytes=409),\n",
       " PathDataV1(_path='lib/python3.7/site-packages/cymem/cymem.cpython-37m-x86_64-linux-gnu.so', path_type='hardlink', sha256='R36ORe5NmBlxQLAFXySgI6lEqlY899mV4iQek3H2Cbo', size_in_bytes=61176),\n",
       " PathDataV1(_path='lib/python3.7/site-packages/cymem/cymem.pxd', path_type='hardlink', sha256='3a6VyWkQ-d6GelUOGNtdTAAg2ksWKjW9mUMu5UzR2zc', size_in_bytes=779),\n",
       " PathDataV1(_path='lib/python3.7/site-packages/cymem/cymem.pyx', path_type='hardlink', sha256='NjYVjVg1HisdH8RIoCLc7CMOGMmQ7mknyl5Ztcd8XOQ', size_in_bytes=5343),\n",
       " PathDataV1(_path='lib/python3.7/site-packages/cymem/tests/__pycache__/test_import.cpython-37.pyc', path_type='hardlink', sha256=None, size_in_bytes=None),\n",
       " PathDataV1(_path='lib/python3.7/site-packages/cymem/tests/test_import.py', path_type='hardlink', sha256='QP4VhFs618LeiJvBSEfZh3deETbWxuzir1mEfL-fOV0', size_in_bytes=263))"
      ]
     },
     "execution_count": null,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "read_python_record(whl.parent, fwhl.record_path, '3.7')['paths_data'].paths"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['cymem/cymem.pxd',\n",
       " 'cymem/cymem.pyx',\n",
       " 'cymem/__init__.py',\n",
       " 'cymem/__init__.pxd',\n",
       " 'cymem/cymem.cpython-37m-x86_64-linux-gnu.so',\n",
       " 'cymem/about.py',\n",
       " 'cymem/tests/test_import.py',\n",
       " 'cymem-2.0.2.dist-info/METADATA',\n",
       " 'cymem-2.0.2.dist-info/LICENSE',\n",
       " 'cymem-2.0.2.dist-info/RECORD',\n",
       " 'cymem-2.0.2.dist-info/top_level.txt',\n",
       " 'cymem-2.0.2.dist-info/WHEEL']"
      ]
     },
     "execution_count": null,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fwhl.namelist()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from wheel.metadata import pkginfo_to_metadata"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "meta = fwhl.read(f'{fwhl.dist_info_path}/METADATA').decode()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('Metadata-Version', '2.1'),\n",
       " ('Name', 'cymem'),\n",
       " ('Version', '2.0.2'),\n",
       " ('Summary', 'Manage calls to calloc/free through Cython'),\n",
       " ('Home-page', 'https://github.com/explosion/cymem'),\n",
       " ('Author', 'Matthew Honnibal'),\n",
       " ('Author-email', 'matt@explosion.ai'),\n",
       " ('License', 'MIT'),\n",
       " ('Platform', 'UNKNOWN'),\n",
       " ('Classifier', 'Environment :: Console'),\n",
       " ('Classifier', 'Intended Audience :: Developers'),\n",
       " ('Classifier', 'Intended Audience :: Science/Research'),\n",
       " ('Classifier', 'License :: OSI Approved :: MIT License'),\n",
       " ('Classifier', 'Operating System :: POSIX :: Linux'),\n",
       " ('Classifier', 'Operating System :: MacOS :: MacOS X'),\n",
       " ('Classifier', 'Operating System :: Microsoft :: Windows'),\n",
       " ('Classifier', 'Programming Language :: Cython'),\n",
       " ('Classifier', 'Programming Language :: Python :: 2.6'),\n",
       " ('Classifier', 'Programming Language :: Python :: 2.7'),\n",
       " ('Classifier', 'Programming Language :: Python :: 3.3'),\n",
       " ('Classifier', 'Programming Language :: Python :: 3.4'),\n",
       " ('Classifier', 'Programming Language :: Python :: 3.5'),\n",
       " ('Classifier', 'Programming Language :: Python :: 3.6'),\n",
       " ('Classifier', 'Programming Language :: Python :: 3.7'),\n",
       " ('Classifier', 'Topic :: Scientific/Engineering')]"
      ]
     },
     "execution_count": null,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m = Parser().parsestr(meta)\n",
    "m.items()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[(0, 'cymem/cymem.pxd'),\n",
       " (1, 'cymem/cymem.pyx'),\n",
       " (2, 'cymem/__init__.py'),\n",
       " (3, 'cymem/__init__.pxd'),\n",
       " (4, 'cymem/cymem.cpython-37m-x86_64-linux-gnu.so'),\n",
       " (5, 'cymem/about.py'),\n",
       " (6, 'cymem/tests/test_import.py'),\n",
       " (7, 'cymem-2.0.2.dist-info/METADATA'),\n",
       " (8, 'cymem-2.0.2.dist-info/LICENSE'),\n",
       " (9, 'cymem-2.0.2.dist-info/RECORD'),\n",
       " (10, 'cymem-2.0.2.dist-info/top_level.txt'),\n",
       " (11, 'cymem-2.0.2.dist-info/WHEEL')]"
      ]
     },
     "execution_count": null,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "zip_ref = zipfile.ZipFile(whl,\"r\")\n",
    "ls = zip_ref.filelist\n",
    "[(i,o.filename) for i,o in enumerate(ls)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Wheel-Version: 1.0\n",
      "Generator: bdist_wheel (0.32.1)\n",
      "Root-Is-Purelib: false\n",
      "Tag: cp37-cp37m-manylinux1_x86_64\n",
      "\n",
      "\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'cymem-2.0.2.dist-info/WHEEL'"
      ]
     },
     "execution_count": null,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fn = ls[11]\n",
    "f = zip_ref.read(fn)\n",
    "print(f.decode())\n",
    "fn.filename"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
